package com.shun.controller.api

import com.shun.entity.Machine
import com.shun.entity.User
import com.shun.service.MachineService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

/**
 * Created by rainbow on 2017/8/31.
 *一事专注，便是动人；一生坚守，便是深邃！
 */
@RestController
@RequestMapping("/api/v1/machine")
class MachineController {

    @Autowired
    private lateinit var service: MachineService

    @PostMapping
    fun create(@SessionAttribute("user") user: User, @RequestBody params: Machine) = service.create(params, user)

    @GetMapping
    fun list(@RequestParam params: Map<String, Any?>) = service.list(params)

    @PostMapping("/modify/{machineCode}")
    fun modify(@PathVariable machineCode: String, @RequestBody params: Map<String, Any>) = service.modify(machineCode, params)

    @PutMapping("/save")
    fun save(@RequestBody params: Map<String, String>) = service.save(params)

    @GetMapping("/info/{machineCode}")
    fun info(@PathVariable machineCode: String) = service.info(machineCode)

    @GetMapping("/query/{machineCode}")
    fun query(@PathVariable machineCode: String) = service.query(machineCode)
}